/**
 * @file    Expression classname is undefined on line 2, column 15 in Templates/Classes/Class.java.
 * @author  Haseeb Yousaf
 * @see     LICENSE (MIT style license file)
 * @version 1.0
 * @date    Nov 18, 2011 1:24:01 AM
 */
package carrello.model.association;

import carrello.model.entities.*;
import java.util.Set;
import static carrello.util.EntityManagerUtil.getEntityManager;
public class InvoiceProcessedByPaymentProcessor {
    private Set<Invoice> invoices;
    private Invoice invoice;
    private PaymentProcessor processor;
    
    public InvoiceProcessedByPaymentProcessor()
    {}
    
    public InvoiceProcessedByPaymentProcessor(PaymentProcessor processor, Set<Invoice> invoices)
    {
        this.invoices = invoices;
        this.processor = processor;
    }
    
    public InvoiceProcessedByPaymentProcessor(PaymentProcessor processor, Invoice invoice)
    {
        this.invoice = invoice;
        this.processor = processor;
    }
    /**
     * Saves a many to one association 
     */
    public void saveAll() 
    {
        getEntityManager().beginUnitOfWork();
        this.invoice.setProcessor(processor);
        for ( Invoice inv : invoices)
        {
           inv.setProcessor(this.processor);
           getEntityManager().update(inv);
        }
        getEntityManager().update(processor);
        getEntityManager().endUnitOfWork();
    }
    
    /**
     * deletes the association 
     */
    public void deleteAll() 
    {
        getEntityManager().beginUnitOfWork();
        getEntityManager().removeAll(processor.getInvoice());
        getEntityManager().remove(processor);
        getEntityManager().endUnitOfWork();
    }
    
    public void delete() {}
    /**
     * updates the association
     */
    public void update() {}
    /**
     * saving a one to one relationship
     */
    public void save()
    {
        getEntityManager().beginUnitOfWork();
        invoice.setProcessor(processor);
        getEntityManager().store(invoice);
        getEntityManager().store(processor);
        getEntityManager().beginUnitOfWork();
    }
    
//    public static void main(String[] args)
//    {
//        new ProductBelongsToCategory().delete();
//    }
}